package cn.dota2info.elk.user.service;


import cn.dota2info.elk.user.entity.BaseResponse;
import cn.dota2info.elk.user.dao.UserInfoDao;
import cn.dota2info.elk.user.entity.UserInfo;
import cn.dota2info.elk.user.utils.JwtHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;


/**
 * <p>
 * 服务类
 * </p>
 *
 * @author lw
 * @since 2018-07-27 11:35:48
 */
@Service
public class UserInfoService {

    private static Logger logger = LoggerFactory.getLogger(UserInfoService.class);

    @Autowired
    private UserInfoDao userInfoDao;

    @Value("${base64Security}")
    private String base64Security;

    public Mono<BaseResponse> login(String userName, String passWord){
        UserInfo userInfo=userInfoDao.findFirstByNameAndPassword(userName,passWord);
        if(userInfo==null){
           return Mono.just(new BaseResponse<>(400001, "用户名或密码错误"));
        }
        String token=JwtHelper.createJWT(userInfo.getName(),userInfo.getId().toString()
            ,"admin","admin",3600000,base64Security);
        return  Mono.just(new BaseResponse<>(200, token));

    }

}
